package exam;

/**
 * @Author 刘牌
 * @Date 2020/2/8 0008 14:37
 * @Version 1.0
 */
abstract class Car{
    protected String Suspension;//悬架
    public abstract void setEngine(Engine engine);
    public abstract void speed(int type);
    public abstract void display();
}
abstract class Engine{
    String power;//发动机型号
    protected int speed;//转速
    public Engine(String power){
        this.power=power;
    }
    public int getSpeed() {
        return speed;
    }
    public void setSpeed(int speed) {
        this.speed = speed;
    }
    public abstract void up(int spead) ;
}
class V6 extends Engine{
    public final static int MAX=3000;
    public V6() {
        super("6 缸");
    }
    public void up(int spead) {
        int currentSpeed=this.speed+spead; if(currentSpeed<MAX) {
            this.speed+=spead; }else { this.speed=MAX;
        }
    }
}
class SUVCar extends Car{
    public SUVCar(Engine engine) {
        this.engine=engine;
    }
    Engine engine;
    @Override
    public void setEngine(Engine engine) {
        this.engine=engine;
    }
    @Override
    public void speed(int type) {
        switch (type) {
            case 1:
                engine.up(500);
                break;
            case 2:
                engine.up(1000);
                break;
            case 3:
                engine.up(2000);
                break;
            default: break;
        }
    }
    public void display() {
        System.out.println("当前转速:"+engine.getSpeed());
    }
}
class E4 {
    public static void main(String[] args) {
        Engine engine=new V6();
        Car car=new SUVCar(engine);
        car.speed(1);
        car.speed(2);
        car.speed(3);
        car.display();
    }
}

